//
//  BHHomeCircleItemCell.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/6/9.
//

import UIKit

class BHHomeCircleItemCell: UICollectionViewCell {
    
    @IBOutlet weak var cover_imgView: UIImageView!
    
    @IBOutlet weak var iconBtn: UIButton!
    
    @IBOutlet weak var videoBtn: UIButton!
    
    @IBOutlet weak var title_label: UILabel!
    
    @IBOutlet weak var user_name_label: UILabel!
    
    @IBOutlet weak var likeBtn: UIButton!
    
    // 圈子列表
    var circleModel: BHCircleListModel! {
        didSet {
            if circleModel.resourceType == 2 { // 视频
                self.cover_imgView.sd_setImage(with: URL.init(string: circleModel.extraUrl), completed: nil)
            }else { //  图片
                self.cover_imgView.sd_setImage(with: URL.init(string: circleModel.circleUrl), completed: nil)
            }
            
            self.videoBtn.isHidden = circleModel.resourceType != 2
            self.title_label.text = circleModel.title
            self.user_name_label.text = circleModel.userName
            self.iconBtn.sd_setImage(with: URL.init(string: circleModel.userAvatar), for: .normal, placeholderImage: nil, options: .retryFailed, context: nil)
            self.likeBtn.setTitle("\(circleModel.supportNumber) ", for: .normal)
            self.likeBtn.setTitle("\(circleModel.supportNumber) ", for: .selected)
            
            self.likeBtn.isSelected = circleModel.likeFlag == 1
        }
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.addLayerCorner(12, 0, .white)
        self.iconBtn.addLayerCorner(10, 0, .white)

    }

    static var circleHeight: CGFloat {
        get {
            let halfW = (UIScreen.width-40)/2.0
            let radius: CGFloat = 223/167.5
            return halfW*radius
        }
    }

}
